package com.ang.mockmvc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ssang
 * @date 2022-01-21 9:21
 */
@Controller
public class TestController {
    @Autowired
    RestTemplate restTemplate;

    @ResponseBody
    @RequestMapping("/template/test")
    public Map<String,Object> test(){
        Map<String,Object> resMap = new HashMap<>();

//        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
        String url = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionCountry";

//        ResponseEntity<Map> entity = restTemplate.getForEntity(url, Map.class);
//        Map map = entity.getBody();
//        resMap.put("map",map);

//        Object o = restTemplate.getForObject(url,Object.class);
//        resMap.put("obj",o);

        String str = restTemplate.getForObject(url,String.class);
//        JSONObject json = JSON.parseObject(str,XXX.class);
        resMap.put("str",str);

        return resMap;
    }

    @ResponseBody
    @GetMapping("/template/get")
    public Map<String,Object> getTest(String username, String password){
        System.out.println("================="+username);
        System.out.println("================="+password);

        Map<String,Object> resMap = new HashMap<>();
        String url = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionCountry";

        String str = restTemplate.getForObject(url,String.class);
        resMap.put("str",str);

        return resMap;
    }

    @ResponseBody
    @PostMapping("/template/post")
    public Map<String,Object> postTest(@RequestBody Map map){
        for(Object key : map.keySet()){
            System.out.println("================="+map.get(key));
        }

        Map<String,Object> resMap = new HashMap<>();
        String url = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionCountry";

        String str = restTemplate.getForObject(url,String.class);
        resMap.put("str",str);

        return resMap;
    }

}
